import Vue from "vue"
import vuex from "vuex"
import {
	setCommissionRatio
} from "@/apis/ratio.js"
import {
	goodsData
} from "@/apis/goods.js"
import {
	goodsList
} from "@/apis/goods.js"
// import {orderList} from "@/apis/order.js"
import { orderGoods } from "@/apis/order.js"
Vue.use(vuex)

export default new vuex.Store({
	state: {
		dataFromApi: 1,
		//产品类目
		productTest: null,
		goodsData: null,
		orderData:[],
		orderGoodsData:[]
	},
	getters: {

	},
	mutations: {
		SET_CESHI(state, data) {
			state.dataFromApi = data;
		},
		//产品类目的mutatiion
		SET_PRODUCT(state, product) {
			state.productTest = product;
		},
		// 商品查询
		SET_GOODS(state, goods) {
			state.goodsData = goods;
		},
		//我的订单
		// SET_ORDER(state,orders){
		// 	state.orderData = orders;
		// }
		// 订单里面的商品
		SET_ORDERGOODS(state,order){
			state.orderGoodsData = order;
		}
	},
	actions: {
		async getUserInfo({
			commit
		}, preload) {
			const res = await setCommissionRatio(preload);
			commit('SET_CESHI', res.code);
			// console.log('haohaoi', res.code)
			// console.log('context', commit);
			// console.log('preload', preload);
		},
		async productTestApi({
			commit
		}) {
			const res = await goodsData();
			if (res.code == 200) {
				commit('SET_PRODUCT', res.data);
			}
		},
		//商品
		// async goodsDataApi({
		// 	commit
		// }, preload) {
		// 	const goodsData = await goodsList(preload);
		// 	// console.log('uuuuuuuu',goodsData.data.records)
		// 	if (goodsData.code == 200) {
		// 		commit('SET_GOODS', goodsData.data.records);
		// 	}
		// }
		//我的订单
		// async myOrderList({
		// 	commit
		// }) {
		// 	const res = await orderList();
		// 	if (res.code == 200) {
		// 		console.log('res.data.records',res.data.records)
		// 		commit('SET_ORDER', res.data.records);
		// 	}
		// }
		
		// 订单里面的商品
		async orderGoodsAction({commit},list){
				const res = await orderGoods();
				if (res.code == 200) {
					commit('SET_ORDERGOODS', res.data);
				}
		}
		
	}
})